﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VehicleManagement.Models;
using VehicleManagement.Codes;
using System.Collections;
using VehicleManagement.ControllersServices;

namespace VehicleManagement.Controllers
{
    public class QuarterCostController : Controller
    {
        CarInfoServices carServices = new CarInfoServices();

        //
        // GET: /QuarterCost/RepairCost/2011
        /// <summary>
        /// 维修财务视图
        /// </summary>
        /// <param name="id">选择的年份</param>
        /// <returns></returns>
        public ActionResult RepairCost(int id, string carNumber = "AllCar")
        {
            Hashtable ht = new Hashtable();
            ht.Add("selectYear", id.ToString());
            ht.Add("nextYear", (id + 1).ToString());

            int carID = 0;
            if (!carNumber.Equals("AllCar"))
            {
                carID = carServices.GetCarIdByCarNum(carNumber);
            }
            ht.Add("carID", carID.ToString());

            IList<QuarterCost> listRepairCost = SqlMapperManager.Instance.Get().QueryForList<QuarterCost>("SELECT_YEAR_RepairCost", ht);
            return View(listRepairCost);
        }

        //
        // GET: /QuarterCost/AddOilCost/2011
        /// <summary>
        /// 加油财务视图
        /// </summary>
        /// <param name="id">选择的年份</param>
        /// <returns></returns>
        public ActionResult AddOilCost(int id, string carNumber = "AllCar")
        {
            Hashtable ht = new Hashtable();
            ht.Add("selectYear", id.ToString());
            ht.Add("nextYear", (id + 1).ToString());

            int carID = 0;
            if (!carNumber.Equals("AllCar"))
            {
                carID = carServices.GetCarIdByCarNum(carNumber);
            }
            ht.Add("carID", carID.ToString());

            IList<QuarterCost> listAddOilCost = SqlMapperManager.Instance.Get().QueryForList<QuarterCost>("SELECT_YEAR_AddOilCost", ht);
            return View(listAddOilCost);
        }

        //
        // GET: /QuarterCost/Accident/2011
        /// <summary>
        /// 事故财务视图
        /// </summary>
        /// <param name="id">选择的年份</param>
        /// <returns></returns>
        public ActionResult Accident(int id, string carNumber = "AllCar")
        {
            Hashtable ht = new Hashtable();
            ht.Add("selectYear", id.ToString());
            ht.Add("nextYear", (id + 1).ToString());

            int carID = 0;
            if (!carNumber.Equals("AllCar"))
            {
                carID = carServices.GetCarIdByCarNum(carNumber);
            }
            ht.Add("carID", carID.ToString());

            IList<QuarterCost> listAccident = SqlMapperManager.Instance.Get().QueryForList<QuarterCost>("SELECT_YEAR_Accident", ht);
            return View(listAccident);
        }

        //
        // GET: /QuarterCost/AllQuarterCost/2011
        /// <summary>
        /// 维修、加油、事故财务视图
        /// </summary>
        /// <param name="id">选择的年份</param>
        /// <returns></returns>
        public ActionResult AllQuarterCost(int id, string carNumber = "AllCar")
        {
            if (id == 0)
            {
                id = DateTime.Now.Year;
            }
            Hashtable ht = new Hashtable();
            ht.Add("selectYear", id.ToString());
            ht.Add("nextYear", (id + 1).ToString());

            int carID = 0;
            if (!carNumber.Equals("AllCar"))
            {
                carID = carServices.GetCarIdByCarNum(carNumber);
            }
            ht.Add("carID", carID.ToString());

            ListQuarterCost listQuarterCost = new ListQuarterCost();

            listQuarterCost.listRepairCost = SqlMapperManager.Instance.Get().QueryForList<QuarterCost>("SELECT_YEAR_RepairCost", ht);
            listQuarterCost.listAddOilCost = SqlMapperManager.Instance.Get().QueryForList<QuarterCost>("SELECT_YEAR_AddOilCost", ht);
            listQuarterCost.listAccident = SqlMapperManager.Instance.Get().QueryForList<QuarterCost>("SELECT_YEAR_Accident", ht);
            return View(listQuarterCost);
        }
    }
}
